import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/goods/Login.vue'
import Home from '../components/Home.vue'
import welcome from '../components/welcome.vue'
import Moudule from '../components/moudle/moudle.vue'
import user from '../components/users/user.vue'
import role from '../components/role/role.vue'
Vue.use(VueRouter)

const routes = [{
		path: '/',
		redirect: 'login'

	},
	{
		path: '/Login',
		name: 'login',
		component: Login
	},
	{
		path: '/Home',	
		component: Home,
		redirect:'/welcome',
		children:[{
			path: '/welcome',
			component:welcome
		},
		{
			path: '/moudule',
			component:Moudule
		},
		{
			path: '/user',
			component:user
		},
		{
			path: '/role',
			component:role
		}
		
		
		
			
		]
	}
]

const router = new VueRouter({
	routes
})

//挂载路由导航守卫
router.beforeEach((to, from, next) => {
	//to将要访问的路径
	//form 代表从那个路径跳转而来
	//next 是一个函数表示放行
	if (to.path == '/Login') return next();

	//获取token
	const mytoken = window.sessionStorage.getItem('token');
	if (!mytoken) return next('/Login');
	next();




})

export default router
